import requests
from bs4 import BeautifulSoup

url = "http://www.crazyant.net"
r = requests.get(url)
if r.status_code != 200:
    raise Exception

demo = r.text

# soup = BeautifulSoup(demo, "html.parser")
soup = BeautifulSoup(demo, "lxml")
# demo 表示被解析的html格式的内容    html.parser表示解析用的解析器

h2_nodes = soup.find_all("h2", class_="entry-title")

for h2_node in h2_nodes:
    link = h2_node.find("a")
    print(link["href"], link.get_text())
